package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.LevelDto;
import com.zzyl.service.LevelService;
import com.zzyl.vo.LevelVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
public class LevelController extends BaseController{

    @Autowired
    private LevelService levelService;

    /**
     * 条件分页查询护理项目
     * @param pageNum 当前页码
     * @param pageSize 每页记录数
     * @param name 护理等级名称
     * @param status 护理等级的状态
     *
     */
    @ApiOperation(value = "条件分页查询护理等级",notes = "根据护理等级名称和状态进行分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<LevelVo>> selectByPage(
            @ApiParam(value = "当前页码，用于指定要查询的页数", required = true) Integer pageNum,
            @ApiParam(value = "每页显示的记录数，用于控制每页包含的护理等级数量", required = true) Integer pageSize,
            @ApiParam(value = "护理等级的名称，可选参数，用于根据等级名称进行查询过滤") String name,
            @ApiParam(value = "护理等级的状态，可选参数，用于根据等级状态进行查询过滤") Integer status){


        return success(levelService.selectByPage(pageNum,pageSize,name,status));

    }

    @PostMapping("/insert")
    public ResponseResult<LevelVo> addLevel(@RequestBody LevelDto levelDto) {
        return toAjax(levelService.addLevel(levelDto));
    }

    @PutMapping("/update")
    public ResponseResult<LevelVo> updateLevel(@RequestBody LevelDto levelDto) {
        return toAjax(levelService.updateLevel(levelDto));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult<LevelVo> deleteLevel(@PathVariable Integer id) {
        return toAjax(levelService.deleteLevel(id));
    }

    @GetMapping("/{id}")
    public ResponseResult<LevelVo> selectLevelById(@PathVariable Long id) {
        return success(levelService.selectLevelById(id));
    }

    @GetMapping("/listAll")
    public ResponseResult<List<LevelVo>> selectAll() {
        return success(levelService.selectAll());
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult<LevelVo> updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        return success(levelService.updateStatusById(id,status));
    }


}
